package org.example.curriculum_design_6_16.controller;

import org.example.curriculum_design_6_16.entity.vo.Result;
import org.example.curriculum_design_6_16.entity.pojo.PaperScoringRule;
import org.example.curriculum_design_6_16.service.PaperScoringRuleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/paperScoringRule")
public class PaperScoringRuleController {
    @Autowired
    private PaperScoringRuleService paperScoringRuleService;

    @PostMapping
    public Result<Integer> addPaperScoringRule(@RequestBody PaperScoringRule rule) {
        try {
            return Result.success(paperScoringRuleService.addPaperScoringRule(rule));
        } catch (Exception e) {
            return Result.error("添加论文评分规则失败: " + e.getMessage());
        }
    }

    @PutMapping
    public Result<Integer> updatePaperScoringRule(@RequestBody PaperScoringRule rule) {
        try {
            return Result.success(paperScoringRuleService.updatePaperScoringRule(rule));
        } catch (Exception e) {
            return Result.error("更新论文评分规则失败: " + e.getMessage());
        }
    }

    @DeleteMapping("/{id}")
    public Result<Integer> deletePaperScoringRule(@PathVariable Integer id) {
        try {
            return Result.success(paperScoringRuleService.deletePaperScoringRule(id));
        } catch (Exception e) {
            return Result.error("删除论文评分规则失败: " + e.getMessage());
        }
    }

    @GetMapping("/{id}")
    public Result<PaperScoringRule> getPaperScoringRuleById(@PathVariable Integer id) {
        try {
            return Result.success(paperScoringRuleService.getPaperScoringRuleById(id));
        } catch (Exception e) {
            return Result.error("获取评分规则失败: " + e.getMessage());
        }
    }

    @GetMapping
    public Result<List<PaperScoringRule>> getAllPaperScoringRules() {
        try {
            return Result.success(paperScoringRuleService.getAllPaperScoringRules());
        } catch (Exception e) {
            return Result.error("获取所有评分规则失败: " + e.getMessage());
        }
    }

    @GetMapping("/PaperType")
    public Result getAllPaperType() {
        try {
            return Result.success(paperScoringRuleService.getAllType());
        } catch (Exception e) {
            return Result.error("获取所有刊物会议类型失败: " + e.getMessage());
        }
    }
}